RAIS  3.2
C:/Projekte/RAIS/ApplicationLogiLayer/Localisation.cs
Go to the documentation of this file.
00001 
00028 using System;
00029 using System.Collections.Generic;
00030 using System.Text;
00031 
00032 using Cultures = System.Collections.Generic.Dictionary<string, RAIS.Common.Localization.Culture>;
00033 using Contexts = System.Collections.Generic.Dictionary<string, RAIS.Common.Localization.Context>;
00034 using TranslationItems = System.Collections.Generic.Dictionary<string, RAIS.Common.Localization.TranslationItem>;
00035 
00036 namespace RAIS.ApplicationLogicLayer
00037 {
00041     public class Localisation
00042     {
00043         #region Static fields
00044         private static string untranslatedPrefix = "(UNTR ";
00045         #endregion
00046         #region Public static properties
00047 
00054         public static Cultures SupportedLanguages
00055         {
00056             get
00057             {
00058                 return DataAccessLayer.Localisation.SupportedLanguages;
00059             }
00060         }
00068         public static Contexts Contexts
00069         {
00070             get
00071             {
00072                 return DataAccessLayer.Localisation.Contexts;
00073             }
00074         }
00075         #endregion
00076 
00092         #region Public static methods
00093         public static string Translate(string textToTranslate, string translationContext, string sourceLanguage, string targetLanguage)
00094         {
00095             try
00096             {
00097                 string translatedText = DataAccessLayer.Localisation.Translate(translationContext, textToTranslate, sourceLanguage, targetLanguage);
00098                 if (translatedText.Length == 0 && textToTranslate.Length != 0)
00099                     return textToTranslate;
00100                 else
00101                     return translatedText;
00102             }
00103             catch
00104             {
00105                 return textToTranslate;
00106             }
00107         }
00115         public static bool AddCulture(RAIS.Common.Localization.Culture culture, ref string returnMessage)
00116         {
00117             return  ValidateNewCulture(culture, ref returnMessage) &&
00118                     DataAccessLayer.Localisation.AddCulture(culture, ref returnMessage);
00119         }
00127         public static bool SaveCulture(RAIS.Common.Localization.Culture culture, ref string returnMessage)
00128         {
00129             return DataAccessLayer.Localisation.SaveCulture(culture, ref returnMessage);
00130         }
00138         public static bool DeleteCulture(RAIS.Common.Localization.Culture culture, ref string returnMessage)
00139         {
00140             return DataAccessLayer.Localisation.DeleteCulture(culture, ref returnMessage);
00141         }
00147         public static TranslationItems GetAllTranslations(  RAIS.Common.Localization.Culture sourceLanguage, 
00148                                                             RAIS.Common.Localization.Culture targetLanguage,
00149                                                             bool untranslatedOnly,
00150                                                                                                                         string sortExpression, 
00151                                                                                                                         string sortDirection)
00152         {
00153             return DataAccessLayer.Localisation.GetAllTranslations(sourceLanguage, targetLanguage, untranslatedOnly, sortExpression, sortDirection);
00154         }
00160         public static TranslationItems GetTranslationsByContext(RAIS.Common.Localization.Context context, 
00161                                                                 RAIS.Common.Localization.Culture sourceLanguage,
00162                                                                 RAIS.Common.Localization.Culture targetLanguage, 
00163                                                                 bool untranslatedOnly,
00164                                                                                                                                 string sortExpression,
00165                                                                                                                                 string sortDirection)
00166         {
00167                         return DataAccessLayer.Localisation.GetTranslationsByContext(context, sourceLanguage, targetLanguage, untranslatedOnly, sortExpression, sortDirection);
00168         }
00176         public static bool SaveTranslations(TranslationItems translations, ref string returnMessage)
00177         {
00178             return DataAccessLayer.Localisation.SaveTranslations(translations, ref returnMessage);
00179         }
00180         #endregion
00181         #region Private static helper methods
00182 
00190         static bool ValidateNewCulture(RAIS.Common.Localization.Culture culture, ref string returnMessage)
00191         {
00192             if (RAIS.DataAccessLayer.Localisation.CultureExists(culture.Name))
00193             {
00194                 returnMessage = Common.Messages.CULTURE_EXISTS;
00195                 return false;
00196             }
00197             else
00198             {
00199                 return true;
00200             }
00201         }
00214         private static string Untranslated(string textToTranslate, string targetLanguage)
00215         {
00216             return untranslatedPrefix + targetLanguage + ") " + textToTranslate;
00217         }
00224         private static bool IsUntranslated(string textToTranslate)
00225         {
00226             return textToTranslate.IndexOf(untranslatedPrefix) == 0;
00227         }
00228         #endregion
00229     }
00230 }